home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # names2dos [-DEBUG | -d | -V | -L | -help ] directory_name
- trap 'rm -f $TMP $CHANGECONTENTS $CHANGECONTENTS_SED $CHANGENAMES_DIR $CHANGENAMES $AWK_SCRIPT; echo "$NAME received signal. Exiting." ; exit 1 '1 2 3 6 9 15
-
- VERSION=" $Header: /users/bergman/Bin/Names2Dos/RCS/names2dos,v 2.1 1993/04/13 04:01:33 bergman Exp bergman $"
- NAME=`basename $0`
-
- #
- #
-
-
- # **********************************************************************
- # * *
- # * names2dos Copyright (c) 1993 Mark Bergman *
- # * *
- # * This program is free software; you can redistribute it and/or *
- # * modify it under the terms of the GNU General Public License as *
- # * published by the Free Software Foundation; either version 2 of *
- # * the License, or (at your option) any later version. *
- # * *
- # * This program is distributed in the hope that it will be useful, *
- # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- # * GNU General Public License for more details. *
- # * *
- # * You should have received a copy of the GNU General Public *
- # * License along with this program; if not, write to the Free *
- # * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, *
- # * USA. *
- # * *
- # * *
- # * Mark Bergman *
- # * bergman@panix.com *
- # * ...!{uunet,cmcl2}!panix!bergman *
- # * 718-855-9148 *
- # * *
- # **********************************************************************
-
-
- #
- # This script is designed to walk through a directory tree and
- # change filenames to conform to MS-DOS standards. It attempts
- # to generate unique filenames, and will change all references
- # to invalid names _within files_ to the newly created names.
- # The script requires a modern version of awk--nawk or gnu awk
- #
- # The script creates one file, changelog, to record the
- # changes made to the directory tree.
- #
- # The companion awk script takes a file or
- # directory name, with a path, and returns the original name
- # and a unique, DOS compatible name to stdout, in the format:
- # path_long_names/files_long_names path_lon/files_lo
- # Unchanged names are _not_ returned by the awk script.
- #
-
- # Initialization
- AWK=nawk # Command for "smart" awk, possibly nawk or gawk
- SED=gsed # Command for sed. Gnu sed PREFERRED
- LOG=changes.log
- AWK_SCRIPT=/tmp/$NAME.$$.awk
- TMP=/tmp/$NAME.$$
- CHANGENAMES=/tmp/changenames.$$
- CHANGENAMES_DIR=/tmp/changenames.dir.$$
- CHANGECONTENTS=/tmp/changecontents.$$
- CHANGECONTENTS_SED=/tmp/changecontents.sed.$$
- DEBUG=FALSE
- DEVICES=FALSE
- # Get options.
- #
- while [ $# -ne 0 ]
- do
- case $1 in
- -DEBUG)
- DEBUG=TRUE
- shift;;
- -d)
- DEVICES=TRUE
- shift;;
- -help | -h | "-?")
- echo ""
- echo "Usage: $NAME [-DEBUG | -d | -V | -L | -help ] directory_name"
- echo "$NAME will walk the directory tree and change all file and directory"
- echo "names to conform to MS-DOS standards. Any references to invalid names"
- echo "within files will also be changed."
- echo ""
- echo "Options:"
- echo " -DEBUG Produce verbose output while processing and save"
- echo " intermediate files."
- echo " -d DOS devices. Changes references to /dev devices (null,"
- echo " tty) to acceptable DOS versions (nul, con). This"
- echo " option will result in files that are incompatible"
- echo " under Unix."
- echo " -V Version. Print the current version of $NAME."
- echo " -L Limits. Print the limits of $NAME."
- echo " -help Help. Display this message."
- echo ""
- echo " A backup copy of the directory tree you plan to change should"
- echo " be made prior to running $NAME."
- echo ""
- exit 0;;
- -V)
- VERSION=`echo $VERSION|$SED -e "s/^.*,v//" -e "s/Exp.*//"`
- echo "${0} version: $VERSION"
- # O.K., this is an ugly hack. I grep for the comment that identifies
- # the version of the awk script, but grep will also return the line
- # with the grep command itself! I must throw away the first line that
- # grep receives, and only process the second.
- AWK_VERSION=`grep AWK_SCRIPT_VERSION $0 | $SED -e "1d" -e "s/^.*,v//" -e "s/Exp.*//"`
- echo "${0} awk script version: $AWK_VERSION"
- exit 0;;
- -L)
- echo "$NAME limits: system imposed limits on $SED, $AWK. Maximum"
- echo "of 41 variations will be created to avoid collisions in the case"
- echo "of non-unique names."
- exit 0;;
- -*)
- echo "Unrecognized option: $1."
- echo "Usage: $NAME [-DEBUG | -d | -V | -L | -help ] directory_name"
- exit 1;;
-
- *)
- break;;
- esac
- done
-
-
- # Check for correct number of arguments (1)
- if [ $# -ne 1 ]
- then
- echo "Usage: $NAME [-DEBUG | -d | -V | -L | -help ] directory_name"
- exit
- fi
-
- # Well, the arguments _look_ good...
-
- ROOT=$1
- # Check to see if $ROOT is a sane choice
- if [ ! -d $ROOT -o ! -x $ROOT -o ! -w $ROOT ]
- then
- echo Usage: $NAME directory_name
- echo " $ROOT must be a directory where you have read, write,"
- echo " and execute (cd) permission"
- exit 2
- fi
-
- if [ ! -w . ]
- then
- echo Usage: $NAME directory_name
- echo " You must have write permission in the currrent directory"
- echo " to create the $NAME log file."
- exit 3
- fi
-
- if [ $DEBUG = TRUE ]
- then
- echo Writing awk script to $AWK_SCRIPT
- fi
-
- # O.K., we have a reasonable ROOT, write the awk script into a
- # temporary file
- cat > $AWK_SCRIPT << 'E-O-AWK'
- #################################################################
- # AWK SCRIPT BEGINS
- #################################################################
- # This awk script REQUIRES the "new" awk. It may be called
- # awk, nawk, or gawk on your particular system.
- #
- # awk script. Designed to be run by names2dos
- # script. This awk script will accept filenames output from
- # "find" and produce a paired list of the original filenames
- # and DOS naming convention acceptable filenames.
- # Files/directories that don't need to be changed are not
- # printed.
- # AWK_SCRIPT_VERSION: $Header: /users/bergman/Bin/Names2Dos/RCS/names2dos.awk,v 2.0 1993/04/11 23:36:01 bergman Exp $
- #
- #
- # Revision 1.0 1993/03/21 19:54:05 bergman
-
- # Please send any comments/questions/bug fixes to:
- # Mark Bergman
- # bergman@panix.com
- # ...{uunet,cmcl2}!panix!bergman
- #
- #
-
- BEGIN { FS="/"
- NUMNAMES=0
- VALIDCHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_~!$"
- NUMVALID=41
- USEDNAMES[0]=""
- }
- # Split each line at the slash (/)
- {
- # For each component of the path, make a valid filename
- # Only call filename2dos on the last component of each
- # pathname
- newname=""
- for ( i = 1 ; i <= NF ; i++)
- {
- if ( i == NF )
- {
- # We are at the _last_ component
- # in the pathname
- newname=newname filename2dos($i)
- }
- else
- {
- # We are somewhere in a multi-part path
- newname=newname $i "/"
- }
- }
-
- # Check to see if we really had to change the name...
- if ( $0 != newname )
- {
- # Yes, a new filename was created... Now check to
- # see that it is really unique!
-
- # Set the "number of duplicates" counter to 0
- numdupes=0
- while ( CheckNameSpace(newname,USEDNAMES,NUMNAMES) == "FALSE" )
- {
- # We have a duplicate name (otherwise we
- # wouldn't be here) so increment the numdupes
- # counter
- # numdupes is the index into the VALIDCHARS
- # array, pointing at a different character in
- # each attempt to generate a unique filename.
-
- numdupes++
-
- # Check to see if we've exhausted the
- # list of alternate characters for the last
- # letter in the basename without finding a
- # unique name. This would only happen in the
- # case where there are already 41 unique files
- # in the form
- # xxxxxxxN
- # where N is a different character from the
- # set of VALIDCHARS for each filename. There
- # may be some MS-DOS acceptable characters
- # that I have ommitted from VALIDCHARS, but
- # who cares?
-
- if ( numdupes == NUMVALID )
- {
- printf("No unique name has been generated for %s.\nRename %s manually.\n",$0,$0)
- exit(numdupes)
- }
-
- # As long as we run into duplicate names,
- # change the last letter on the base of the
- # name to try to find a unique name
-
- newname=ChangeName(newname,numdupes,VALIDCHARS)
- }
- NUMNAMES++
- printf("%s %s\n",$0,newname)
- }
- else
- {
- # O.K., the supplied name fits the 8.3 naming
- # scheme, but we still have to add it to the
- # list of USEDNAMES to avoid future duplicates.
- NUMNAMES++ # increment the number of unique names
- USEDNAMES[NUMNAMES]=newname
- }
- }
- END{}
-
- function filename2dos(FiLeNaMe)
- {
- # take a filename and make it dos-legal:
- # name[.extension]
- # where
- # name is 8 characters or less
- # does not contain any illegal characters
- # where
- # extension
- # is 3 characters of less
- # does not contain any illegal characters
- #
- # return a legal DOS filename
- #
- # Initialization
-
- components=""
- NAMEpart=""
- DOSname=""
- EXTENSIONpart=""
- DOSextension=""
- FILENAME=""
-
- # Begin...
- # Take given FiLeNaMe (possible mixed case) and change
- # to an all upper-case "FILENAME"
- FILENAME = changecase(FiLeNaMe,"upper")
-
- # If the first character in the filename is a "." make it an "_"
- sub(/^\./,"_",FILENAME)
- # If the last character in the filename is a "." make it an "._"
- sub(/\.$/,"._",FILENAME)
-
- # Split the FILENAME into different components separated by periods
- components=split(FILENAME,nameparts,".")
-
- # There will always be at least a name part
-
- NAMEpart=nameparts[1]
-
- if ( components == 1 )
- {
- DOSname=substr(NAMEpart,1,8)
- gsub(/[ `@#%^&*()+={}\[\]:;"'<>,.?\/\\|]/,"-",DOSname)
- # The above gsub attempts to remove all
- # characters that are illegal in DOS filenames.
- # This will probably fail miserably on true Posix
- # 2.0 compliant 8-bit clean filenames. Tough luck.
- # You can add high order characters, etc. to the
- # above set, but I wanted to avoid the pain in the
- # butt involved in making this a binary file as far
- # as mail and downloading were concerned.
- }
-
- if ( components == 2 )
- {
- EXTENSIONpart=nameparts[2]
- DOSextension=substr(EXTENSIONpart,1,3)
- gsub(/[ `@#%^&*()+={}\[\]:;"'<>,.?\/\\|]/,"-",DOSextension)
-
- DOSname=substr(NAMEpart,1,8)
- gsub(/[ `!@#%^&*()+={}\[\]:;"'<>,.?\/\\|]/,"-",DOSname)
- DOSname=DOSname "." DOSextension
- }
-
- if ( components > 2 )
- {
- # Convert names in the form:
- # base.1.2.3.extension
- # to:
- # base_1_2.ext
-
-
- for ( j = 2 ; j < components ; j++)
- {
- if ( length(NAMEpart) <=6 )
- {
- NAMEpart=NAMEpart "_" nameparts[j]
- }
- else
- {
- NAMEpart=NAMEpart nameparts[j]
- }
- }
- EXTENSIONpart=nameparts[j]
- DOSextension=substr(EXTENSIONpart,1,3)
- gsub(/[ `!@#%^&*()+={}\[\]:;"'<>,.?\/\\|]/,"-",DOSextension)
-
- DOSname=substr(NAMEpart,1,8)
- gsub(/[ `!@#%^&*()+={}\[\]:;"'<>,.?\/\\|]/,"-",DOSname)
- DOSname=DOSname "." DOSextension
- }
- return(DOSname)
- }
-
- function CheckNameSpace(Newname,Convertnames,Numnames)
- {
- # Check the list of new file names to see
- # if the current name is a duplicate
-
- # Assume that the generated name passed to this
- # routine is unique
- Uniquename="TRUE"
-
- for ( j = 1 ; j <= Numnames ; j++ )
- {
- # Loop through the list of all the names
- # we've generated so far.
- if ( Newname == Convertnames[j] )
- {
- Uniquename="FALSE"
- j = Numnames # Exit the loop
- }
- }
- if ( Uniquename=="TRUE" )
- {
- # If we got through the list of all the
- # converted filenames and Newname is still
- # unique, add it to the list.
- Convertnames[j]=Newname
- }
- return(Uniquename)
- }
-
-
- function ChangeName(newname,numdupes,VALIDCHARS)
- {
- # Given a name in the form
- # base.extension
- # that is already DOS acceptable but is a duplicate of
- # an existing name, change the last character in the
- # base to try to create a new name.
- # We will get clever enough to _add_ characters to the
- # base if it is less than 8 chars
- # This routine is not clever enough to pad out the
- # extension to produce filenames that are fully 8.3 in an
- # attempt to generate a unique name. At a worst case, 40
- # filenames will be created. Mucking with the extension
- # might be a bad idea, because so many extensions, like
- # .c, have real meaning.
-
- # First of all, split up the full path+filename that we
- # are given so that we can easily muck with just the
- # filename.
- Name2ChangePosition=split(newname,PATHCOMPONENTS,"/")
- Name2Change=PATHCOMPONENTS[Name2ChangePosition]
-
- baselength=index(Name2Change,"\.")
- if ( baselength > 0 )
- {
- # There is an extension that must be split
- # from the base name
- split(Name2Change,NAMEPARTS,"\.")
- base = NAMEPARTS[1]
- extension = NAMEPARTS[2]
- baselength=length(base)
- if ( baselength < 8 )
- {
- # If the base is less than 8 characters,
- # add the next character from the
- # VALIDCHARS set to the end of the base
- base=base substr(VALIDCHARS,numdupes,1)
- }
- else
- {
- # The base is 8 characters. Substitute
- # the last character in the base with the
- # character from the VALIDCHARS set that
- # the numdupes index is pointing to.
- sub(/.$/,substr(VALIDCHARS,numdupes,1),base)
- }
- # Re-build the complete filename
- Name2Change=base "." extension
- }
- else
- {
- # There is no extension...Name2Change is the base
- newnamelength=length(Name2Change)
- if ( newnamelength < 8 )
- {
- Name2Change=Name2Change substr(VALIDCHARS,numdupes,1)
- }
- else
- {
- sub(/.$/,substr(VALIDCHARS,numdupes,1),Name2Change)
- }
- }
-
- # Now we've got another filename to pass back to
- # the main routine and test for uniqueness again. We must
- # rebuild the path+[new]filename.
-
- newname=PATHCOMPONENTS[1] # There is always at least 1 component
- # and this avoids adding a leading /
- PATHCOMPONENTS[Name2ChangePosition]=Name2Change
- for ( z= 2 ; z <= Name2ChangePosition ; z++ )
- {
- newname=newname "/" PATHCOMPONENTS[z]
- }
- return(newname)
- }
- function changecase(string,newcase)
- #
- # Changes the case of the given string to the specified case
- # Example:
- # LINE = changecase($0,"upper")
-
- {
-
- if ( newcase != "upper" && newcase != "lower" )
- {
- return(NULL)
- }
- else
- {
- RESULT = ""
- Ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- Lcase = "abcdefghijklmnopqrstuvwxyz"
-
- for(i=1;i <= length(string);i++)
- {
- if ( newcase == "upper" )
- {
- if( (cpos = index(Lcase,c = substr(string,i,1))) > 0)
- {
- c = substr(Ucase,cpos,1);
- }
- }
- else
- {
- if( (cpos = index(Ucase,c = substr(string,i,1))) > 0)
- {
- c = substr(Lcase,cpos,1);
- }
- }
- RESULT = RESULT c;
- }
- return (RESULT)
- }
- }
- #################################################################
- # AWK SCRIPT ENDS
- #################################################################
- E-O-AWK
-
- # Run the find once to list Directory names and shove those
- # names through the awk script.
-
- if [ $DEBUG = TRUE ]
- then
- echo Collecting directory names from $ROOT
- fi
-
- find $ROOT -type d -print | $AWK -f $AWK_SCRIPT > $TMP
- echo "$NAME run on $ROOT" > $LOG
-
- # Run the value for ROOT through the awk script in case
- # that was one of the changed directory names.
-
- NEWROOT=`echo $ROOT|$AWK -f $AWK_SCRIPT |$SED -e 's/^.* //' `
- # If $ROOT does not need to change, then NEWROOT will be null
- if [ "$NEWROOT" != "" ]
- then
- ROOT=$NEWROOT
- if [ -d $ROOT -o -f $ROOT ]
- then
- # That's it! My patience is exhausted!
- echo ${NAME}: $ROOT must be removed to proceed.
- exit
- fi
- if [ $DEBUG = TRUE ]
- then
- echo $ROOT will change to $NEWROOT
- fi
- fi
-
- # If the TMP file isn't empty, there are directory names to change...
- while [ -s $TMP ]
- do
-
- # This is a loop because the script will fail to rename
- # subdirectories of renamed directories. For example, given:
- # invalid_directory/bad_subdirectory/file1
- # the first iteration through the loop would generate a
- # script with the commands:
- # #!/bin/sh
- # mv -f invalid_directory invalid_
- # mv -f invalid_directory/bad_subdirectory invalid_/bad_subd
- # The second "mv" command would fail because the parent directory
- # invalid_directory no longer exists. The loop will change
- # directory names untill all names are DOS acceptable. Not too
- # clean, but easy.
-
- if [ $DEBUG = TRUE ]
- then
- echo Changing directory names
- fi
-
- echo "" >> $LOG
- echo "Recursive directory name changes:" >> $LOG
- cat $TMP >> $LOG
-
- # Build the script to do the changes
- echo "#!/bin/sh" > $CHANGENAMES_DIR
-
- # The following sed command:
- # substitutes the last <SPACE> followed by a
- # vaild MS-DOS filename for a <PLUS-SIGN>
- # followed by the same name.
- #
- # Then substitute all other <SPACE>s (which
- # must be imbedded in the invalid filename)
- # with \<SPACE> to escape the meaning of
- # <SPACE> for the mv command.
- #
- # Substitute a <SPACE> back in place of the
- # <PLUS SIGN> added earlier
- #
- # escapes shell metacharacters: ( ) * ? $ ! ~ "
- #
- # adds "mv " to the beginning of each line
- #
-
- $SED -e 's@\(.*\) \([A-Za-z0-9_\-~!\$/][0-9A-Za-z_\-~!\$\./]*\)@\1+\2@' -e 's@ @\\ @g' -e 's@\(.*\)+\([0-9A-Za-z_\-~!\$/][0-9A-Za-z_\-~!\$\./]*\)@\1 \2@' -e 's@\([][()*$!~"?]\)@\\\1@g' -e 's/^/mv -f /' $TMP >> $CHANGENAMES_DIR
-
- # Make the script executable
- chmod +x $CHANGENAMES_DIR
-
- # Do the changes to directory names
-
- $CHANGENAMES_DIR 2> /dev/null
- # There may be a lot of errors. Whenever a parent
- # directory name is changed, all attempts to change child
- # subdirectory names will fail. This is why error messages
- # are thrown away and why the directory-name change
- # section may be run repeatedly.
-
- if [ $DEBUG = FALSE ]
- then
- rm -f $TMP $CHANGENAMES_DIR
- else
- echo Collecting directory names again to search for additional invalid names
- fi
-
- # Run the "find" again now that we've changed something.
-
- find $ROOT -type d -print | $AWK -f $AWK_SCRIPT > $TMP
- done
-
-
- # Run the find again to change file names, now that
- # directory names won't conflict under 8.3
-
- if [ $DEBUG = TRUE ]
- then
- echo Directory name changes complete
- echo Collecting filenames
- fi
-
- find $ROOT -type f -print | $AWK -f $AWK_SCRIPT > $TMP
- echo "" >> $LOG
- echo "File name changes:" >> $LOG
- cat $TMP >> $LOG
-
- # Create a script to effect all the file name changes
- echo "#!/bin/sh" > $CHANGENAMES
-
- # The following sed command:
- # Replace <SPACE> with #;#
- # #;# was chosen because it is approximately unique in a
- # filename--both unlikely and difficult to put into a filename.
- #
- # Replace last #;# on the line w. <SPACE>
- # The last <SPACE> (now a #;#) is always the separator
- # between the original and converted pathnames.
- #
- # Then substitute all other <SPACE>s (which
- # must be imbedded in the invalid filename)
- # with \<SPACE> to escape the meaning of
- # <SPACE> for the mv command.
- #
- # Substitute a <SPACE> back in place of the
- # #;# added earlier
- #
- # escapes shell metacharacters: ( ) * ? $ ! ~ "
- #
- # adds "mv " to the beginning of each line
- #
-
- $SED -e 's@ @#;#@g' -e 's@#;#\([^#;#]*\)$@ \1@' -e 's@#;#@\\ @g' -e 's@\([][()*$!~"?]\)@\\\1@g' -e 's/^/mv -f /' $TMP >> $CHANGENAMES
-
-
- # Simultaneously, we are building a sed script to change the
- # contents of any files that refer to file names
- # that have been altered. The following command just takes all
- # the filenames that will be changed and strips the paths
- # away. The awk script output in the TMP file in the form:
- # long/non_DOS-useable/path+file.name long/non_DOS-u/path+fil.nam
- # becomes:
- # path+file.name path+fil.nam
- #
- # The following 4 sed commands create another sed file,
- # CHANGECONTENTS_SED, which is used to change the contents of files in
- # the tree. Each sed command takes the output from the awk script, in the
- # form:
- #
- # Original/Bad/Path/and/Non-DOS-filename Good/Path/and/FILENAME.DOS
- #
- # and builds a slightly different sed expression for each entry. The 4
- # different sed lines are necessary because the given Non-DOS-filename
- # may be a subset of many filenames. For example, if the name in
- # question is "Makefile" there may also be "Makefile.fonts",
- # "Makefile.install", etc. If the sed command changed all instances of
- # "Makefile" to "MAKEFILE", then no instances of "Makefile.fonts" would
- # be found.
- #
- # The sed commands each work in the following sequence:
- #
- # Replace <SPACE> with #;#
- # #;# was chosen because it is approximately unique in a
- # filename--both unlikely and difficult to put into a filename.
- #
- # Replace last #;# on the line w. <SPACE>
- # The last <SPACE> (now a #;#) is always the separator
- # between the original and converted pathnames.
- #
- # Delete initial path, leaving only 1st filename
- #
- # Delete 2nd path up to 2nd filename
- #
- # Escape sed metacharacters
- # Put a \ before [ ] \ / . * ^ $
- #
- # Following commands turn Filename1 Filename2 into a sed command
- # Put s/ at the beginning of the line
- # Put /\1 between the two filenames
- #
- # This stage differs slightly for each sed line. Here, the original
- # filename is surrounded by regular expressions to limit how it is found
- # in a line. The regular expressions (in order) are:
- # \([ <>:\\\/][ <>:\\\\\\/]*\)ORIGINAL_FILENAME\([ <>:\\\/][ <>:\\\\\\/]*\)
- # ^ORIGINAL_FILENAME\([ <>:\\\/][ <>:\\\\\\/]*\)
- # \([ <>:\\\/][ <>:\\\\\\/]*\)ORIGINAL_FILENAME$
- # \<ORIGINAL_FILENAME\>
- # Note that the sed built-in regex delimiter pair \< \> is used last.
- # Because many filenames use periods, the idea is to delay matching names
- # delimited by periods until other combinations have been used.
- #
- # Put \2/g after the 2nd filename
- #
- # Convert all #;# back to <SPACE>
- #
-
- $SED -e 's/ /#;#/g' -e 's/#;#\([^#;#]*\)$/ \1/' -e 's@^.*/\(.*\) @\1 @' -e 's@ .*/@ @' -e 's@\([][\.\*\$\^]\)@\\\1@g' -e 's@^@s/@' -e 's@ @/\\1@' -e 's@\/\(.*\)\/@\/\\([ <>:\\\\\\/][ <>:\\\\\\/]*\\)\1\\([ <>:\\\\\\/][ <>:\\\\\\/]*\\)\/@' -e 's@$@\\2/g@' -e 's/#;#/ /g' $TMP > $CHANGECONTENTS_SED
-
- $SED -e 's/ /#;#/g' -e 's/#;#\([^#;#]*\)$/ \1/' -e 's@^.*/\(.*\) @\1 @' -e 's@ .*/@ @' -e 's@\([][\.\*\$\^]\)@\\\1@g' -e 's@^@s/@' -e 's@ @/@' -e 's@\/\(.*\)\/@\/^\1\\([ <>:\\\\\\/][ <>:\\\\\\/]*\\)\/@' -e 's@$@\\1/g@' -e 's/#;#/ /g' $TMP >> $CHANGECONTENTS_SED
-
- $SED -e 's/ /#;#/g' -e 's/#;#\([^#;#]*\)$/ \1/' -e 's@^.*/\(.*\) @\1 @' -e 's@ .*/@ @' -e 's@\([][\.\*\$\^]\)@\\\1@g' -e 's@^@s/@' -e 's@ @/\\1@' -e 's@\/\(.*\)\/@\/\\([ <>:\\\\\\/][ <>:\\\\\\/]*\\)\1$\/@' -e 's@$@/g@' -e 's/#;#/ /g' $TMP >> $CHANGECONTENTS_SED
-
- $SED -e 's/ /#;#/g' -e 's/#;#\([^#;#]*\)$/ \1/' -e 's@^.*/\(.*\) @\1 @' -e 's@ .*/@ @' -e 's@\([][\.\*\$\^]\)@\\\1@g' -e 's@^@s/@' -e 's@ @/@' -e 's@^.*/\(.*\) @\\<\1\\> @' -e 's@$@/g@' -e 's/#;#/ /g' $TMP >> $CHANGECONTENTS_SED
-
- if [ $DEVICES = TRUE ]
- then
- echo "s@/dev/null@/dev/nul@g" >> $CHANGECONTENTS_SED
- echo "s@/dev/tty@/dev/con@g" >> $CHANGECONTENTS_SED
- fi
-
-
- echo "#!/bin/sh" > $CHANGECONTENTS
- cat >> $CHANGECONTENTS << E-O-CAT
- $SED -f $CHANGECONTENTS_SED \$1 > \$\$
- # perform a minor sanity check...
- cmp -s \$1 \$\$
- if [ \$? -eq 1 ]
- then
- # if the sed command had any effect...
- mv -f \$\$ \$1
- echo "\$1 contents changed"
- fi
- rm -f \$\$
- E-O-CAT
-
- chmod +x $CHANGENAMES
-
- if [ $DEBUG = TRUE ]
- then
- echo Effecting file name changes
- fi
-
- # This should not generate any errors. If it does, report
- # and log the error and switch to DEBUG mode to save the
- # file that produced the error.
-
- $CHANGENAMES 2>> $LOG 1>> $LOG
- if [ $? != 0 ]
- then
- echo "ERROR in changnames. See precceding line." >> $LOG
- echo "ERROR in changnames. Switching to DEBUG mode to save $CHANGENAMES"
- echo "Please examine $LOG for details on the error."
- DEBUG=TRUE
- fi
-
- chmod +x $CHANGECONTENTS
-
- if [ $DEBUG = TRUE ]
- then
- echo Effecting changes to the contents of files. This may take a while.
- if [ $DEVICES = TRUE ]
- then
- echo Devices option in effect.
- fi
- fi
-
- echo "" >> $LOG
- if [ $DEVICES = TRUE ]
- then
- echo "Devices option in effect. Files referring to /dev/tty or /dev/null will change." >> $LOG
- fi
- echo "File contents changes:" >> $LOG
- echo "" >> $LOG
- find $ROOT -type f -exec $CHANGECONTENTS {} \; >> $LOG
- if [ $DEBUG = FALSE ]
- then
- rm -f $TMP $CHANGECONTENTS $CHANGECONTENTS_SED $CHANGENAMES_DIR $CHANGENAMES $AWK_SCRIPT
- else
- echo "Leaving:"
- echo " $CHANGECONTENTS $CHANGECONTENTS_SED $CHANGENAMES_DIR $CHANGENAMES $TMP $AWK_SCRIPT"
- fi
-